from aiogram_dialog import DialogManager
from sqlalchemy.ext.asyncio import AsyncSession

from app.database.enums import ServerPrivacy, ServerType
from app.database.services.orders.common import get_order
from app.database.services.servers import get_server


async def server_type_getter(
    db_session: AsyncSession, dialog_manager: DialogManager, **kwargs
):
    order_id: int = dialog_manager.start_data.get("order_id")
    order = await get_order(db_session, order_id, joined=True)
    server = await get_server(db_session, order.proxies[0].server_id)
    if (
        server.proxy_type == ServerType.mobile
        and server.proxy_privacy == ServerPrivacy.private
    ):
        mobile_private = True
    else:
        mobile_private = False

    return {"proxy_is_mobile_private": mobile_private}
